<?php
/*
  $Id: new_articles.php $
  Mefobe Cart Solutions
  http://www.mefobemarket.com

  Copyright (c) 2009 Wuxi Elootec Technology Co., Ltd;  Copyright (c) 2006 osCommerce

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License v2 (1991)
  as published by the Free Software Foundation.
*/

    class osC_Content_videos extends osC_Modules
    {
        var $_title,
        $_code = 'videos',
        $_author_name = 'Mefobe',
        $_author_www = 'http://www.mefobemarket.com',
        $_group = 'content';

/* Class constructor */

        function osC_Content_videos()
        {
            $this->_title = 'Videos';
        }

        function initialize()
        {
            global $osC_Database, $current_category_id, $osC_Template;

            $content_type = 'pages';
            $content_id = $current_category_id;

            $content_id = isset($_GET['articles_id']) && !empty($_GET['articles_id']) ? $_GET['articles_id']
                    : $content_id;
            $content_type = isset($_GET['articles_id']) && !empty($_GET['articles_id']) ? 'articles' : $content_type;

            $content_id = isset($_GET['events_id']) && !empty($_GET['events_id']) ? $_GET['events_id'] : $content_id;
            $content_type = isset($_GET['events_id']) && !empty($_GET['events_id']) ? 'events' : $content_type;

            $content_id = isset($_GET['news_id']) && !empty($_GET['news_id']) ? $_GET['news_id'] : $content_id;
            $content_type = isset($_GET['news_id']) && !empty($_GET['news_id']) ? 'news' : $content_type;

            $pieces = explode("index.php", $_SERVER['SCRIPT_NAME']);

            if ($content_type == 'pages') {
                $Qvideos = $osC_Database->query('select v.*,c.*, atoc.*  from :table_videos v left join :table_content c on v.videos_id = c.content_id left join :table_content_to_categories atoc on atoc.content_id = v.videos_id  where atoc.content_type = "videos" and c.content_type = "videos"');
                $Qvideos->appendQuery('and atoc.categories_id = :categories_id ');
                $Qvideos->bindInt(':categories_id', $current_category_id);
                $Qvideos->bindTable(':table_content_to_categories', TABLE_CONTENT_TO_CATEGORIES);
            }
            else
            {
                $Qvideos = $osC_Database->query('select v.*,c.* from :table_videos v left join :table_content c on v.videos_id = c.content_id where c.content_type = "videos" and v.content_id = :content_id and v.content_type = :content_type');
                $Qvideos->bindValue(':content_id', $content_id);
                $Qvideos->bindValue(':content_type', $content_type);
            }

            $Qvideos->appendQuery('order by c.content_order ');
            $Qvideos->bindTable(':table_videos', TABLE_VIDEOS);
            $Qvideos->bindTable(':table_content', TABLE_CONTENT);
            $Qvideos->execute();

            if ($Qvideos->numberOfRows() > 0) {

                $osC_Template->addJavascriptFilename('ext/swfobject/swfobject.js');

                $i = 0;
                $this->_content .= '<a name="ytplayer"></a>';

                $this->_content .= '<script type="text/javascript">
                                    function ytplayer_loadvideo( id ) {
                                        var o = document.getElementById(\'ytplayer_object\');
                                        if( o ) {
                                            o.loadVideoById( id );
                                        }
                                    }
                                    </script>';
                $videos_list = '';

                while ($Qvideos->next()) {
                   $this->_content .= '<div style = "width:400px"><object style="height: 300px; width: 400px"><param name="movie" value="http://www.youtube.com/v/' . $Qvideos->value('youtube_id');
                        $this->_content .= '?version=3&feature=player_detailpage"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://www.youtube.com/v/' . $Qvideos->value('youtube_id');
                        $this->_content .= '?version=3&feature=player_detailpage" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="400" height="300"></object></div>';
                    

                    $i++;
                }               
            }

            $Qvideos->freeResult();
        }

        function install()
        {
            parent::install();
        }

        function getKeys()
        {
            if (!isset($this->_keys)) {
                $this->_keys = array();
            }

            return $this->_keys;
        }
    }

?>
